package com.zzl.finance.data.dto;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zzl.apidoc.annotation.ApidocModel;
import com.zzl.apidoc.annotation.ApidocModelProperty;
import com.zzl.apidoc.constants.RequiredType;
import com.zzl.finance.data.entity.DataTypeEntity;
import com.zzl.general.common.utils.DoubleSerialize;
import com.zzl.general.common.utils.DoubleToPercentSerialize;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 资金方，即金融机构
 *
 * @author gull
 * @date 2022-07-01 18:23:11
 */
@Data
@ApidocModel
@SuppressWarnings("javadoc")
public class FinanceInstitutyDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApidocModelProperty(description = "金融机构主键")
    private String id;
    @ApidocModelProperty(description = "资金方名称，如XX银行")
    private String instinctyName;
    @ApidocModelProperty(description = "金融产品id")
    private String financialProductId;
    @ApidocModelProperty(description = "金融产品名称")
    private String financialProductName;
    @JsonSerialize(using = DoubleToPercentSerialize.class)
    @ApidocModelProperty(description = "融资年利率")
    private Double annualizedInterestRate;
    @JsonSerialize(using = DoubleToPercentSerialize.class)
    @ApidocModelProperty(description = "平台服务费率")
    private Double platServiceRate;
    @ApidocModelProperty(description = "到账周期，为到账的天数值")
    private Integer receiptPeriod;
    @JsonSerialize(using = DoubleSerialize.class)
    @ApidocModelProperty(description = "预计到账")
    private Double estimateLoanAmount;
    @JsonSerialize(using = DoubleSerialize.class)
    @ApidocModelProperty(description = "融资成本")
    private Double financingCost;
    @JsonSerialize(using = DoubleToPercentSerialize.class)
    @ApidocModelProperty(description = "融资成本利率")
    private Double financingCostRate;
    @JsonSerialize(using = DoubleSerialize.class)
    @ApidocModelProperty(description = "平台服务费用", required = RequiredType.TRUE, example = "10")
    private Double serviceChage;
    @JsonSerialize(using = DoubleSerialize.class)
    @ApidocModelProperty(description = "融资利息", required = RequiredType.TRUE, example = "15")
    private Double annualizedInterest;
    @ApidocModelProperty(description = "融资补充信息列表")
    private List<InstitutyDataTypeDto> dataTypeList;


    public Double getServiceChage() {
        return serviceChage;
    }

    public Double getFinancingCostRate() {
        if (null == annualizedInterestRate) {
            annualizedInterestRate = 0d;
        }
        if (null == platServiceRate) {
            platServiceRate = 0d;
        }
        return annualizedInterestRate + platServiceRate;
    }
}
